import axios from 'axios';

// API基础配置
//const API_BASE_URL = 'http://127.0.0.1:8080/lottery-sys'; // 根据实际后端地址调整
const API_BASE_URL = '/lottery-sys'; // 根据实际后端地址调整
// 创建axios实例
const api = axios.create({
  baseURL: API_BASE_URL,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  }
});

// 抽奖相关API
export const lotteryApi = {
  // 获取抽奖设置
  getSettings: () => api.get('/lottery/game/settings'),

  // 获取中奖记录
  getWinners: () => api.get('/lottery/game/winners'),

  // 开始抽奖
  startLottery: (data) => api.post('/lottery/game/start', data),

  // 重置抽奖
  resetLottery: () => api.post('/lottery/game/reset'),

  // 保存设置
  saveSettings: (data) => api.post('/lottery/game/save-settings', data),

  // 获取抽奖记录列表
  getLotteryRecords: (params) => api.get('/lottery/record', { params }),

  // 获取奖项设置列表
  getPrizeSettings: (params) => api.get('/lottery/setting', { params }),

  // 获取奖项列表
  getPrizes: (params) => api.get('/lottery/prize', { params }),

  // 获取奖项的中奖号码配置
  getWinningNumbers: (settingId) => {
    console.log(`请求中奖号码，settingId: ${settingId}`);
    return api.get(`/lottery/game/winning-numbers/${settingId}`);
  },

  // 保存奖项的中奖号码配置
  saveWinningNumbers: (settingId, winningNumbers) => {
    console.log(`保存中奖号码，settingId: ${settingId}, numbers:`, winningNumbers);
    return api.post(`/lottery/game/winning-numbers/${settingId}`, winningNumbers);
  },

  // 获取所有启用的中奖号码
  getAllWinningNumbers: () => api.get('/lottery/game/all-winning-numbers')
};

export default api;
